// Problem 063: Powerful digit counts
// The 5-digit number, 16807=7^5, is also a fifth power. Similarly, the 9-digit number, 134217728=8^9, is a ninth power.
// How many n-digit positive integers exist which are also an nth power?

package main

import (
	"fmt"
	"math/big"
)

func p063() {
	ans := 1 //1^1=1
	var x int64
	ten := big.NewInt(10)
	for x = 2; x < 10; x++ {
		var n int64 = 1
		p := big.NewInt(x)
		q := big.NewInt(1)
		left := big.NewInt(1)
		right := big.NewInt(1)
		for {
			q.Mul(q, p)
			left.Exp(ten, big.NewInt(n-1), nil)
			right.Exp(ten, big.NewInt(n), nil)
			if q.Cmp(left) > -1 && q.Cmp(right) == -1 {
				ans++
			} else if q.Cmp(left) == -1 {
				break
			}
			n++
		}
	}
	fmt.Println("Problem 063:", ans)
}
